package settingsapp.settings.toggle;

import settingsapp.settings.ClickableSettingChanger;
import android.content.Context;

public abstract class ToggleSettingChanger implements ClickableSettingChanger
{
	protected Context context;
	protected boolean isOn;
	int intRepresentation = -1;
	
	public ToggleSettingChanger(Context context, int intRepresentation)
	{
		this.context = context;
		this.intRepresentation = intRepresentation;
	}
	
	@Override
	public String toString()
	{
		return "0." + intRepresentation;
	}
	
	abstract protected void setValue(boolean value);

	/**
	 * Toggles this setting's value
	 * @return the value after toggle is called
	 */
	private boolean toggle()
	{
		boolean newValue = !getValue();
		setValue(newValue);
		return newValue;
	}
	
	/**
	 * A ToggleSettings click action is simple to toggle
	 */
	public boolean clickAction()
	{
		return toggle();
	}
	
	/**
	 * @return the current value for this class's 
	 * system setting
	 */
	public boolean getValue()
	{
		readValue();
		return isOn;
	}
	
	/**
	 * Sets value from system settings
	 * (must be called before returning value
	 * to be correct)
	 */
	abstract protected void readValue();
	
	/**
	 * retrieve on icon resource id for this setting
	 */
	abstract public int getResourceOn();
	/**
	 * retrieve off icon resource id for this setting
	 */
	abstract public int getResourceOff();
}
